// Copyright DustedPixels.com 2008. All rights reserved.

package com.dustedpixels.asm;

import org.objectweb.asm.ClassAdapter;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.tree.ClassNode;

/**
 * @author micapolos@gmail.com (Michal Pociecha-Los)
 */
public final class SuperclassFolder extends ClassAdapter {
  private final ClassFinder classFinder;

  private ClassNode superClass;
  
  public SuperclassFolder(ClassVisitor out, ClassFinder classFinder) {
    super(out);
    this.classFinder = classFinder;
  }

  @Override
  public void visit(int version, int access, String name, String signature, String superName,
      String[] interfaces) {
    if (!superName.equals("java/lang/Object")) {
      // Find super class and fold it.
      superClass = new ClassNode();
      ClassVisitor out = new SuperclassFolder(superClass, classFinder);
      classFinder.findClass(superName, out);
    }
    
    super.visit(version, access, name, signature, superName, interfaces);
  }

  @Override
  public void visitEnd() {
    for
    // TODO Auto-generated method stub
    super.visitEnd();
  }
}
